/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.util.HashMap;
import java.util.Map;
import libCore.Util;
import models.U_BoxEggModel;
import models.U_EggModel;
import models.U_PenguinModel;
import share.ShareMacros;

/**
 *
 * @author LinhTA
 */
public class Cote implements EntityBase, Comparable {

    public int level;
    public Map<String, Penguin> pegs;
    public Map<Long, Map<String, Egg>> eggs;
    public Box_Egg boxegg;
    public int food;
    public int order;

    @Override
    public void setData(Map<String, Object> obj) {
        level   =   Integer.parseInt(obj.get(ShareMacros.LEVEL).toString());
        pegs    =   U_PenguinModel.parsePegs(Util.obj2Map(obj.get(ShareMacros.PEGS)));
        Map<String, Egg> liatEggs = U_EggModel.parseEggs(Util.obj2Map(obj.get(ShareMacros.EGGS)));
        eggs    =   U_EggModel.parseTimeEggs(liatEggs);
        boxegg  =   U_BoxEggModel.parseEggs(Util.obj2Map(obj.get(ShareMacros.BOXEGG)));
        food    =   Integer.parseInt(obj.get(ShareMacros.FISH).toString());
        order   =   Integer.parseInt(obj.get(ShareMacros.COTES_ORDER).toString());
    }

    public int getLevel() {
        return level;
    }

    //============================== Hieu =======================
    
    //============================== Hieu =======================
    
    @Override
    public Map<String, Object> toAMF() {
        Map<String, Object> data = new HashMap<String, Object>();

        data.put(ShareMacros.LEVEL, level);
        data.put(ShareMacros.FISH, food);
        data.put(ShareMacros.COTES_ORDER, order);
        data.put(ShareMacros.PEGS, U_PenguinModel.toAMF(pegs));
        data.put(ShareMacros.BOXEGG, boxegg.toAMF());
        data.put(ShareMacros.EGGS, U_EggModel.toTimeAMF(eggs));

        return data;
    }

    public static Map<String, String> parseCoteBD(CoteDB cote) {
        Map<String, String> data = new HashMap<String, String>();

        data.put(ShareMacros.LEVEL, cote.level);
        data.put(ShareMacros.PEGS, cote.pegs);
        data.put(ShareMacros.BOXEGG, cote.boxegg);
        data.put(ShareMacros.EGGS, cote.eggs);
        data.put(ShareMacros.COTES_ORDER, cote.order);
        return data;
    }

    @Override
    public int compareTo(Object o) {
        return 0;
    }

    public static class CoteDB {

        public String level;
        public String pegs;
        public String eggs;
        public String boxegg;
        public String fish;
        public String order;

        public CoteDB() {
        }

        public void setData(Map<String, String> obj) {
            level   =   String.valueOf( obj.get(ShareMacros.LEVEL) );
            eggs    =   obj.get(ShareMacros.EGGS);
            pegs    =   obj.get(ShareMacros.PEGS);
            boxegg  =   obj.get(ShareMacros.BOXEGG);
            fish    =   obj.get(ShareMacros.FISH);
            order   =   obj.get(ShareMacros.COTES_ORDER);
        }
    }
}
